What is SQL?
SQL stands for Structured Query Language
SQL lets you access and manipulate databases
SQL is an ANSI (American National Standards Institute) standard
SQL has other functions such as:
SQL can execute queries against a database
SQL can retrieve data from a database
SQL can insert records in a database
SQL can update records in a database
SQL can delete records from a database
SQL can create new databases
SQL can create new tables in a database
SQL can create stored procedures in a database
SQL can create views in a database
SQL can set permissions on tables, procedures, and views
SQL perform the following functions such as
SELECT, UPDATE, DELETE, INSERT, WHERE
SQL is a standard language for storing, manipulating and retrieving data in databases.
SQL could be used in the following database systems:
namely, MySQL, SQL Server, MS Access, Oracle, Sybase, Informix, Postgres, and other database systems.
To be able to run SQL, one has to structure the database properly.
For SQL to run a programm in the DB, one has to structure the Table.
Every table is broken up into smaller entities called fields. The fields in the Customers table consist of:
CustomerID, CustomerName, ContactName, Address, City and PostalCode.
A field is a column in a table that is designed to maintain specific information about every record in the table.
This is an example of a customers table in a DB:
CustomerID
CustomerName
ContactName
Address
City
PostalCode
Country
Example
SELECT * FROM Computer kids Academy;
this sql statement says, select all (*) from Computer Kids Academy
there are a number of SQL commands that every user should get used to.
Example:
Some of The Most Important SQL Commands
SELECT - extracts data from a database
UPDATE - updates data in a database
DELETE - deletes data from a database
INSERT INTO - inserts new data into a database
CREATE DATABASE - creates a new database
ALTER DATABASE - modifies a database
CREATE TABLE - creates a new table
ALTER TABLE - modifies a table
DROP TABLE - deletes a table
CREATE INDEX - creates an index (search key)
DROP INDEX - deletes an index
The SELECT statement is used to select data from a database.
The data returned is stored in a result table, called the result-set.
SELECT Column Example
The following SQL statement selects the "CustomerName" and "City" columns from the "Customers" table:
Example
SELECT CustomerName, City FROM Customers;
your table will look like this:
CustomerName
City
Freddy
Berlin
Ana
Bomako
peter
México
john
London
Lhh
The SQL SELECT DISTINCT Statement
The SELECT DISTINCT statement is used to return only distinct (different) values.
Inside a table, a column often contains many duplicate values;
and sometimes you only want to list the different (distinct) values.
The SELECT DISTINCT statement is used to return only distinct (different) values.
(SELECT DISTINCT column2, column5, ...
FROM table_name; )
Example
SELECT City FROM Customers;
Berlin
Bomako
México
London
SELECT country FROM Customers;
SELECT Age FROM Customers;
The SQL WHERE Clause
The WHERE clause is used to filter records.
The WHERE clause is used to extract only those records that fulfill a specified condition.
WHERE Syntax
SELECT column1, column2, ...
FROM table_name
WHERE condition;
Note:
The WHERE clause is not only used in SELECT statement, it is also used in UPDATE, DELETE statement, etc.!